<template>
	<div class="center">
		<el-card shadow="hover" class="register-main">
			<div slot="header" class="clearfix register-header"><span>管理员注册</span></div>
			<el-form :model="form" label-width="60px">
				<el-form-item label="编号"><el-input v-model="form.id"></el-input></el-form-item>
				<el-form-item label="姓名"><el-input v-model="form.name"></el-input></el-form-item>
				<el-form-item label="密码"><el-input v-model="form.password" type="password" show-password></el-input></el-form-item>
				<el-form-item label="性别">
					<el-select v-model="form.sex" placeholder="请选择">
						<el-option key="男" label="男" value="男"></el-option>
						<el-option key="女" label="女" value="女"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="电话"><el-input v-model="form.telephone"></el-input></el-form-item>
				<el-form-item label="职位">
					<el-select v-model="form.duty" placeholder="请选择">
						<el-option v-for="item in $store.state.duties" :key="item" :label="item" :value="item"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="生日"><el-date-picker v-model="form.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker></el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">立即创建</el-button>
					<router-link to="/"><el-button type="infor">取消</el-button></router-link>
				</el-form-item>
			</el-form>
		</el-card>
	</div>
</template>

<script>
export default {
	data() {
		return {
			form: {
				id: '',
				password: '',
				sex: '',
				name: '',
				duty: '',
				telephone: '',
				birthday: ''
			}
		};
	},
	methods: {
		onSubmit() {
			let that = this;
			console.log(that.form);
			that.axios
				.post(that.$store.state.serverHost + '/administrator/register/', that.form)
				.then(res => {
					console.log(res);
					if (res.data == '注册成功') {
						that.$message({
							message: res.data,
							type: 'success'
						});
						setTimeout(()=>{
							that.$router.go(-1)
						},1000)
						return
					}
					that.$message.error(res.data)
					
				})
				.catch(e => {
					that.$message.error("注册失败")
				});
		}
	}
};
</script>

<style scoped>
.center {
	height: 100vh;
}
.register-main {
	width: 50vw;
	height: 80vh;
}
.register-header {
	color: #409eff;
	font-size: 1.5em;
	text-align: center;
}
</style>
